//
//  HMPersonViewController.m
//  localLife
//
//  Created by Limonwei on 15/11/27.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HMPersonViewController.h"
#import "UIImageView+WebCache.h"
#import "HMLoginModel.h"
#import "HMLoginoutView.h"

@interface HMPersonViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate,HMLoginoutViewDelegate>;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *orderButton;
@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UIButton *exitButton;
@property (weak, nonatomic) IBOutlet UIButton *infoButton;
@property (weak, nonatomic) IBOutlet UIButton *passWordButton;

@property(nonatomic,strong)HMLoginoutView *loginout;

@end

@implementation HMPersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titltLabel.text = @"个人中心";
    self.rightButton.hidden = YES;
    
    _iconImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changePhoto)];
    
    [_iconImageView addGestureRecognizer:tap];
    
    //[_iconImageView sd_setImageWithURL:[NSURL URLWithString:[HMLoginModel shareInstance].small_avatar]];
    
    _iconImageView.layer.masksToBounds = YES;
    _iconImageView.layer.cornerRadius = _iconImageView.frame.size.width / 2;
    
    //_nameLabel.text = [HMLoginModel shareInstance].user_name;
    
//    if ([[HMLoginModel shareInstance].gender intValue]==1) {
//        _sexLabel.text = @"男";
//    }else{
//        _sexLabel.text = @"女";
//    }
    
    //_phoneLabel.text = [HMLoginModel shareInstance].mobile;
    
    _infoButton.layer.cornerRadius = 5;
    _infoButton.backgroundColor = [UIColor blueColor];
    
    _passWordButton.layer.cornerRadius = 5;
    _passWordButton.backgroundColor = [UIColor blueColor];
    
    _exitButton.layer.cornerRadius = 5;
    _exitButton.backgroundColor = Login_Deep_Color;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)changePhoto{
    
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相机" otherButtonTitles: @"相册",nil];
    [sheet showInView:self.view];
    
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
        //
        UIImagePickerController *picker = [[UIImagePickerController alloc]init];
        
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        //
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }else{
        return;
    }
    
    picker.delegate = self;
    
    [self presentViewController:picker animated:YES completion:^{
        //
    }];
    
    
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    
    [picker dismissViewControllerAnimated:YES completion:^{
        //
    }];
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    [app.tabbar showOrHiddenTabbarView:NO];
}
- (IBAction)exitButton:(id)sender {
    
    _loginout = [[[UINib nibWithNibName:@"HMLoginoutView" bundle:nil]instantiateWithOwner:self options:nil]objectAtIndex:0];
    
    _loginout.delegate = self;
    
    _loginout.frame = [UIScreen mainScreen].bounds;
    
    [[UIApplication sharedApplication].keyWindow addSubview:_loginout];
    
    
}

-(void)didLoginout{
    
    [_loginout removeFromSuperview];
    
}

-(void)didCanale{
    
    [_loginout removeFromSuperview];
}

@end




















